<script type="text/javascript" src="${base}/scripts/page/yg_content.js"></script>
<script type="text/javascript">
    $(function () {
        //加载所属机构树
        $("#yg_ssjg").combotree({
            //panelWidth: 250,
            panelHeight: 150,
            onChange: function (newValue, oldValue) { //级联
                var data = [];
                var tree = $("#yg_ssjg").combotree("tree");
                $(tree.tree("getChecked")).each(function (index, value) {
                    data.push({id: this.id, text: this.text});
                });
                $("#yg_zgjg").combobox("loadData", data);
                var zgjgId = $("#yg_zgjg").combobox("getValue");
                //如果选择的元素中没有主管机构则清空主管机构
                if ($.grep(data,function (e, i) {
                    return e.id == zgjgId
                }).length == 0)
                    $("#yg_zgjg").combobox("clear");

                },
            onLoadSuccess: function () { //初始化值
                var zgjgId = $("#yg_zgjg").val()
                var ssjgList = $("#defaultValue input[name='yg_ssjgList']").map(function () {
                    return $(this).val();
                });
                $("#yg_ssjg").combotree('setValues', ssjgList);
                var data = [];
                var tree = $("#yg_ssjg").combotree("tree"); //此时的this实际上是tree加载的是tree的数据
                $(tree.tree("getChecked")).each(function (index, value) {
                    data.push({id: this.id, text: this.text});
                });
                $("#yg_zgjg").combobox("loadData", data);
                if (zgjgId)
                    $("#yg_zgjg").combobox("setValue", zgjgId);
            },
            loadFilter: function (rows) {
                return convert(rows);
            }
        });

        $("#yg_zgjg").combobox({
            onChange: function (newValue, oldValue) { //级联
                $.ajax({ //一个Ajax过程
                    type: "post", //以post方式与后台沟通
                    url: $.webPath() + "/organ/gsjg/findGsOrJg",
                    dataType: 'text', //从php返回的值以 JSON方式 解释
                    data: {jgId: newValue}, //发给php的数据有两项，分别是上面传来的u和p
                    success: function (data) {//如果调用php成功
                        if (data == "2") {
                            $("input[name='yg.cxfw']").eq(2).attr("disabled", false);
                        } else {
                            if ($("input[name='yg.cxfw']").eq(2).is(":checked"))
                                $("input[name='yg.cxfw']").eq(3).attr("checked", true);
                            $("input[name='yg.cxfw']").eq(2).attr("disabled", true);
                        }
                    }
                });
            }
        });
        //加载直属上级
        $("#yg_zssj").combogrid({
            panelWidth: 430,
            idField: 'id',
            textField: 'xm',
            url: '${base}/sys/yg/ygList',
            pagination: true,
            fit: true,
            columns: [
                [
                    {field: 'xm', title: '姓名', width: 60},
                    {field: 'gh', title: '工号', width: 100},
                    {field: 'zgjg_qc', title: '主管机构', width: 120},
                    {field: 'ssjgList_jc', title: '所属机构', width: 100}
                ]
            ]
        });
        //加载角色
        $("#yg_js").combobox({
            onLoadSuccess: function () {
                var jsList = $("#defaultValue input[name='yg_jsList']").map(function () {
                    return $(this).val();
                });
                $("#yg_js").combobox('setValues', jsList);


                if($("#currentYg_Id").val() != 1)
                    $("#yg_js").combobox('readonly',true);
            }
        });

        //加载包含仓库
        $("#yg_ssck").combogrid({
            idField: 'id',
            textField: 'mc',
            url: '${base}/organ/ck/ckmcList?ssgsjgId='+$("#ygZgGsId").val(),
            multiple: true,
            editable: false,
            fit: true,
            columns: [
                [
                    {field: 'mc', title: '仓库名称', width: 80},
                    {field: 'ckjb', title: '仓库类型', width: 80,formatter:function(value){
                        if(value==1){
                            return "经营仓库";
                        }else if(value==2){
                            return "保供仓库";
                        }else if(value==3){
                            return "三方仓库";
                        }
                    }}
                ]
            ],
            onLoadSuccess: function () {
                var ckList = $("#defaultValue input[name='yg_ckList']").map(function () {
                    return $(this).val();
                });
                $("#yg_ssck").combogrid('setValues', ckList);
            }
        });

        //加载所属岗位
        $("#yg_ssgw").combogrid({
            idField: 'id',
            textField: 'mc',
            url: '${base}/sys/gwpz/gwpzAllList?gsjgId='+$("#ygZgGsId").val(),
            multiple: true,
            editable: false,
            fit: true,
            columns: [
                [
                    {field: 'mc', title: '岗位名称', width: 60},
                    {field: 'ms', title: '描述', width: 100}
                ]
            ],
            onChange: function (newValue, oldValue) { //级联
                var data = [];
                var grid = $("#yg_ssgw").combogrid("grid");
                $(grid.datagrid("getSelections")).each(function (index, value) {
                    data.push({id: this.id, text: this.mc});
                });
                $("#yg_zygw").combobox("loadData", data);
                var zygwId = $("#yg_zygw").combobox("getValue");
                //如果选择的元素中没有主管机构则清空主管机构
                if ($.grep(data,function (e, i) {
                    return e.id == zygwId
                }).length == 0)
                    $("#yg_zygw").combobox("clear");

            },
            onLoadSuccess: function () { //初始化值
                var zygwId = $("#zygw_id").val();
                var ssgwList = $("#defaultValue input[name='yg_ssgwList']").map(function () {
                    return $(this).val();
                });
                //ssgwList是jquery数组不能Join使用makeArray方法强转  //将一个数组类对象转化为真正的JavaScript数组。
                $("#yg_ssgw").combogrid('setValues', $.makeArray(ssgwList));
                var data = [];
                var grid = $("#yg_ssgw").combogrid("grid");
                $(grid.datagrid("getSelections")).each(function (index, value) {
                    data.push({id: this.id, text: this.mc});
                });
                $("#yg_zygw").combobox("loadData", data);
                if (zygwId)
                    $("#yg_zygw").combobox("setValue", zygwId);
            }
        });

        $("#yg_zssj_id").ygSearch({
            treeUrl: "${base}/organ/gsjg/gsjg_tree",
            gridUrl: "${base}/sys/yg/ygList",
            columns: [
                [
                    {field: 'xm', title: '姓名', align: 'center', width: 8},
                    {field: 'gh', title: '工号', align: 'center', width: 8},
                    {field: 'zgjg_jc', title: '所属机构', align: 'center', width: 12}
                ]
            ],
            inputName: 'yg.zssj.id'
        });
//        //在职和可登陆关联
//        $('[name="yg.sfzz"]').change(function() {
//            var index = $(this).parent().index();
//            $('[name="yg.kdl"]:eq('+index+')').attr("checked","checked");
//        });
    });
</script>

<div id="defaultValue" style="display: none;">
<#if (yg.ckList)??>
    <#list yg.ckList as ssck>
        <#if (ssck.id)??>
            <input type="hidden" name="yg_ckList" value="${(ssck.id)!}"/>
        </#if>
    </#list>
</#if>
<#if (yg.ssgwList)??>
    <#list yg.ssgwList as ssgw>
        <#if (ssgw.id)??>
            <input type="hidden" name="yg_ssgwList" value="${(ssgw.id)!}"/>
        </#if>
    </#list>
</#if>
<#if (yg.jsList)??>
    <#list yg.jsList as js>
        <#if (js.id)??>
            <input type="hidden" name="yg_jsList" value="${(js.id)!}"/>
        </#if>
    </#list>
</#if>
<#if (yg.ssjgList)??>
    <#list yg.ssjgList as ssjg>
        <#if (ssjg.id)??>
            <input type="hidden" name="yg_ssjgList" value="${(ssjg.id)!}"/>
        </#if>
    </#list>
</#if>
</div>
<form id="ygForm" method="post">
<input type="hidden" value="${(yg.id)!}" name="yg.id"/>
<input type="hidden" value="${(currentYg.id)!}" id="currentYg_Id"/>
<input type="hidden" value="${(ygZgGsId)!}" id="ygZgGsId"/>
<div class="easyui-tabs">
<div title="基本信息">
    <table style="width:100%" class="tb tab-t">
        <col width="17.5%"/>
        <col width="32.5%"/>
        <col width="17.5%"/>
        <col width="32.5%"/>
        <tr>
            <th style="color:#f45212;">姓&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;名：</th>
            <td>
                <input name="yg.xm" class="easyui-validatebox input-text" type="text"
                       data-options="required:true,validType:['length[0,6]']"
                       value="${(yg.xm)!}"/>
            </td>
            <th style="color:#f45212;">登&nbsp;&nbsp;录&nbsp;名：</th>
            <td>
                <input name="yg.dlm" class="easyui-validatebox input-text" type="text"
                       data-options="required:true,validType:['length[0,6]']" missingMessage="员工登录名不能为空！"
                       validType="remote['${base}/sys/yg/ajax_validate?ygId=${(yg.id)!}',{'validateField':'dlm'},'此登录名已被使用']"
                       value="${(yg.dlm)!}"/>
            </td>
        </tr>

        <tr>
            <th>性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别：</th>
            <td>
                <label><input name="yg.xb" type="radio" value="1"
                              <#if (yg.xb)??><#if yg.xb==1>checked</#if><#else>checked</#if>
                              style="vertical-align: middle;"/>男</label>
                <label><input name="yg.xb" type="radio" value="0"
                              <#if (yg.xb)?? && yg.xb==0>checked</#if> style="vertical-align: middle;"/>女</label>
            </td>

            <th>电话号码：</th>
            <td>
                <input name="yg.dhhm" type="text" class="input-text" data-options="validType:['length[0,100]']"
                       value="${(yg.dhhm)!}"/>
            </td>
        </tr>
        <tr>
            <th>角&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;色：</th>
            <td><input id="yg_js" name="yg.jsList.id" type="text" value="" class="easyui-combobox input-text"
                       data-options="url:'${base}/sys/js/jsmcList', valueField:'id',textField:'mc',editable:false,multiple:true,panelHeight:'100'"/>
            </td>
            <th>可&nbsp;&nbsp;登&nbsp;录：</th>
            <td>
                <label>
                    <input name="yg.kdl" type="radio" value="true" style="vertical-align: middle;"
                           <#--<#if (yg.kdl)?? && yg.kdl==true>checked="checked"</#if>-->checked/>是</label>
                <label>
                    <input name="yg.kdl" type="radio" value="false" style="vertical-align: middle;"
                           <#if (yg.kdl)?? && yg.kdl==false>checked</#if>/>否</label>
            </td>

        </tr>
        <tr>
            <th>所属机构：</th>
            <td>
                <input id="yg_ssjg" name="yg.ssjgList.id" type="text" value="${(nbbm.sjjg.id)!''}"
                       class="easyui-combotree input-text"
                       data-options="url:'${base}/organ/gsjg/gsjg_tree',panelHeight:'100',required:true,multiple:true,cascadeCheck:false"/>
            </td>
            <th>主管机构：</th>
            <td>
                <input id="yg_zgjg" name="yg.zgjg.id" type="text" value="${(yg.zgjg.id)!}"
                       class="easyui-combobox input-text" required="true"
                       data-options="valueField:'id',textField:'text',required:true, multiple:false,panelHeight:'100',editable:false"/>
            </td>
        </tr>

        <tr>
            <th>所属岗位：</th>
            <td>
                <input id="yg_ssgw" name="yg.ssgwList.id" type="text" value="" class="combogrid input-text"/>
            </td>
            <th>主要岗位：</th>
            <td><input id="yg_zygw" name="yg.zygw.id" type="text" value="${(yg.zygw.id)!}"
                       class="easyui-combobox input-text"
                       data-options="valueField:'id',textField:'text', multiple:false,panelHeight:'100',editable:false"/>
            </td>
        </tr>
        <tr>
            <th> 查询范围：</th>
            <td>
                <label><input name="yg.cxfw" type="radio" value="0"
                              <#if (yg.cxfw)?? && yg.cxfw==0>checked</#if>
                              style="vertical-align: middle;"/>全&nbsp;部</label>
                <label><input name="yg.cxfw" type="radio" value="1"
                              <#if (yg.cxfw)?? && yg.cxfw==1>checked</#if>
                              style="vertical-align: middle;"/>本公司 </label>
                <label><input name="yg.cxfw" type="radio" value="2"
                              <#if (yg.cxfw)?? && yg.cxfw==2>checked</#if>
                              style="vertical-align: middle;"/>本部门</label>
                <label><input name="yg.cxfw" type="radio" value="3"
                              <#if (yg.cxfw)??><#if yg.cxfw==3>checked</#if><#else>checked</#if>
                              style="vertical-align: middle;"/>本&nbsp;人</label>
            </td>
            <th>工&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;号：</th>
            <td>
                <input name="yg.gh" class="easyui-validatebox input-text" type="text"    value="${(yg.gh)!}"/>
            </td>
        </tr>
        <tr>
            <th>包含仓库：</th>
            <td>
                <input id="yg_ssck" name="yg.ckList.id" type="text" value="" class="combogrid input-text"/>
            </td>
        </tr>
    </table>
</div>
<div title="其他信息">
    <table style="width:100%" class="tb tab-t">
        <col width="17.5%"/>
        <col width="32.5%"/>
        <col width="17.5%"/>
        <col width="32.5%"/>
        <tr>
            <th>直属上级：</th>
            <td><input class="input-text" id="yg_zssj_id" value="${(yg.zssj.xm)!''}"/>
                <input name="yg.zssj.id" type="hidden" value="${(yg.zssj.id)!''}"/>
            <#--<a href="javascript:void(0)" class="lookup-btn">查询</a>-->
            </td>
            <th>在职情况：</th>
            <td>
                <label><input name="yg.sfzz" type="radio" value="true" checked
                              style="vertical-align: middle;"/>在职</label>
                <label>
                    <input name="yg.sfzz" type="radio" value="false"
                           <#if (yg.sfzz)?? && yg.sfzz==false>checked </#if>
                           style="vertical-align: middle;"/>不在职</label>
            </td>
        </tr>
        <tr>
            <th>档&nbsp;&nbsp;案&nbsp;号：</th>
            <td>
                <input name="yg.dah" type="text" class="input-text" data-options="validType:['length[0,100]']"
                       value="${(yg.dah)!}"/>
            </td>
            <th>婚姻状况：</th>
            <td>
                <label style="margin-right: 10px;"><input name="yg.hyzk" type="radio" value="true"
                                                          <#if (yg.hyzk)?? && yg.hyzk==true>checked="checked"</#if>
                                                          style="vertical-align: middle;"/>已婚</label>
                <label><input name="yg.hyzk" type="radio" value="false" checked="checked"
                              style="vertical-align: middle;"/>未婚</label>
            </td>
        </tr>

        <tr>
            <th>工作分机号：</th>
            <td>
                <input name="yg.gzfjh" type="text" class="input-text" data-options="validType:['length[0,100]']"
                       value="${(yg.gzfjh)!}"/>
            </td>
            <th>政治面貌：</th>
            <td>
                <input name="yg.zzmm" class="input-text" type="text" value="${(yg.zzmm)!''}"/>
            </td>
        </tr>
        <tr>
            <th>用工性质：</th>
            <td>
                <input name="yg.ygxz" class="input-text" type="text" value="${(yg.ygxz)!''}"/>
            </td>
            <th>员工民族：</th>
            <td>
                <input name="yg.mz" class="input-text" type="text" value="${(yg.mz)!''}"/>
            </td>
        </tr>

        <tr>
            <th>出生日期：</th>
            <td>
                <input name="yg.csrq" class="easyui-datebox input-text" type="text" value="${(yg.csrq)!}"/>
            </td>
            <th>排&nbsp;&nbsp;序&nbsp;号：</th>
            <td width="35%">
                <input name="yg.pxh" type="text" class="input-text" class="easyui-numberbox" data-options="min:0"
                       value="${(yg.pxh)!}"/>
            </td>

        </tr>
        <tr>
            <th>入职时间：</th>
            <td>
                <input name="yg.rzsj" class="easyui-datebox input-text" type="text" value="${(yg.rzsj)!}"/>
            </td>
            <th>职&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;称：</th>
            <td>
                <input name="yg.zc" class="input-text" type="text" value="${(yg.zc)!''}"/>
            </td>
        </tr>

        <tr>
            <th>身高和体重：</th>
            <td>
                <div style="white-space:nowrap;height: 20px">
                    <input name="yg.sg" type="text" class="easyui-numberbox input-text" style="width:64px;"
                           data-options="min:0,max:400,precision:4" value="${(yg.sg)!}"/>CM
                    <input name="yg.tz" type="text" class="easyui-numberbox input-text" style="width:64px;"
                           data-options="min:0,max:400,precision:4" value="${(yg.tz)!}"/>KG
                </div>
            </td>
            <th>出&nbsp;&nbsp;生&nbsp;地：</th>
            <td>
                <input name="yg.csd" type="text" class="input-text" data-options="validType:['length[0,100]']"
                       value="${(yg.csd)!}"/>
            </td>
        </tr>

        <tr>
            <th>血&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;型：</th>
            <td>
                <input name="yg.xx" class="input-text" type="text" value="${(yg.xx)!''}"/>
            </td>
            <th>业余爱好：</th>
            <td>
                <input name="yg.ywah" class="input-text" type="text" data-options="validType:['length[0,100]']"
                       value="${(yg.ywah)!}"/>
            </td>
        </tr>

        <tr>
            <th>特&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;长：</th>
            <td>
                <input name="yg.tc" type="text" class="input-text" data-options="validType:['length[0,100]']"
                       value="${(yg.tc)!}"/>
            </td>
            <th>户籍地址：</th>
            <td>
                <input name="yg.hjdz" type="text" class="input-text" data-options="validType:['length[0,100]']"
                       value="${(yg.hjdz)!}"/>
            </td>
        </tr>
    </table>
</div>
</div>
</form>

